<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form
      ref="form"
      size="mini"
      :model="form"
      label-position="top"
      class="myform"
    >
      <div>
        <el-form-item label="调拨计划单/款号/SKU" class="myform-item">
          <el-input
            v-model="form.number"
            placeholder="请输入调拨计划单/款号/SKU"
            clearable
            @keyup.enter.native="onSearch"
          ></el-input>
        </el-form-item>
        <el-form-item label="调拨类型" class="myform-item">
          <el-select v-model="form.groups" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="推送状态" class="myform-item">
          <el-select v-model="form.is_push" placeholder="请选择">
            <el-option
              v-for="item in optionspush"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px" class="myform-item">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
        <el-form-item style="margin-top: 50px" class="myform-item">
          <el-button type="primary" plain @click="onAdd">调拨出库</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-table size="mini" :data="tableData" style="width: 100%" border>
      <el-table-column
        label="调拨计划单"
        align="center"
        prop="allocation_number"
      ></el-table-column>
      <el-table-column
        label="款号"
        align="center"
        prop="type_no"
      ></el-table-column>
      <el-table-column
        label="SKU"
        align="center"
        prop="sku_code"
      ></el-table-column>
      <el-table-column label="调拨类型" align="center" prop="groups">
        <template slot-scope="{ row }">
          {{ row.groups | groupsTitle }}
        </template>
      </el-table-column>
      <el-table-column
        label="计划调拨数量"
        align="center"
        prop="num"
      ></el-table-column>
      <el-table-column
        label="发起人"
        align="center"
        prop="adduser"
      ></el-table-column>
      <el-table-column
        label="发起时间"
        align="center"
        prop="createtime"
      ></el-table-column>
      <el-table-column label="邮寄信息" align="center" prop="wp_user">
        <template slot-scope="{ row }">
          <div v-if="row.wp_user&&row.wp_phone&&row.wp_address">
            {{ row.wp_user + "，" }} {{ row.wp_phone + "，" }}{{ row.wp_province }}{{ row.wp_city }}{{ row.wp_area }}{{ row.wp_address }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="备注信息"
        align="center"
        prop="remark"
      ></el-table-column>
      <el-table-column label="推送状态" align="center" prop="is_push">
        <template slot-scope="{ row }">
          <div v-if="row.is_push == 1" style="color: #67c23a">推送成功</div>
          <div style="color: red" v-else>推送失败</div>
          <el-button
            type="text"
            size="mini"
            v-if="row.is_push != 2"
            @click="onCancelPush(row.allocation_number)"
            >取消推送</el-button
          >
          <el-button type="text" size="mini" v-else disabled
            >已取消推送</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminOmsGetAllocationList"
    />
    <el-dialog
      title="取消推送"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <div>
        <el-radio-group v-model="order_type">
          <el-radio
            :label="item.value"
            v-for="item in optionscancel"
            :key="item.value"
            >{{ item.label }}</el-radio
          >
        </el-radio-group>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button
          type="primary"
          @click="clickOptionscancel"
          :disabled="!order_type"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  postAdminOmsGetAllocationList,
  postAdminAdminOmsCancelAllocation,
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  filters: {
    groupsTitle(e) {
      if (e == 1) return "赠送";
      if (e == 2) return "借出";
      if (e == 3) return "归还";
      return e;
    },
  },
  data() {
    return {
      loading: false,
      dialogVisible: false,
      options: [
        {
          value: "",
          label: "全部",
        },
        {
          value: "1",
          label: "赠送",
        },
        {
          value: "2",
          label: "借出",
        },
        {
          value: "3",
          label: "归还",
        },
      ],
      optionspush: [
        {
          value: "",
          label: "全部",
        },
        {
          value: "0",
          label: "未推送",
        },
        {
          value: "1",
          label: "已推送",
        },
      ],
      optionscancel: [
        {
          value: "JYCK",
          label: "销售订单",
        },
        {
          value: "XTRK",
          label: "销售退货",
        },
        {
          value: "CGRK",
          label: "采购订单",
        },
        {
          value: "CGTH",
          label: "采购退货",
        },
        {
          value: "TRAN",
          label: "调拨计划",
        },
      ],
      order_type: "",
      allocation_number: "",
      form: {
        allocation_number: "",
        number: "",
        groups: "",
        is_push: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
    };
  },
  activated() {
    let form = this.form;
    this.postAdminOmsGetAllocationList(form);
  },
  methods: {
    handleClose() {
      this.order_type = "";
      this.allocation_number = "";
      this.dialogVisible = false;
    },
    async clickOptionscancel() {
      let { order_type, allocation_number } = this;
      let obj = {
        order_type,
        allocation_number,
      };
      try {
        await postAdminAdminOmsCancelAllocation(obj);
        let form = this.form;
        this.postAdminOmsGetAllocationList(form);
      } catch (error) {}
      this.handleClose();
    },
    onCancelPush(allocation_number) {
      this.allocation_number = allocation_number;
      this.dialogVisible = true;
    },
    // 采购列表
    async postAdminOmsGetAllocationList(data) {
      this.loading = true;
      this.form = data;
      postAdminOmsGetAllocationList(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.savetime = res.savetime;
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminOmsGetAllocationList(this.form);
    },
    onAdd() {
      this.$router.push({ name: "PDAdminTransfersAdd" });
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
